package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import util.JDBCUtil;

public class SubjectDaoJDBCImpl implements SubjectDao{

	@Override
	public String getteachername(String coursename) {
		String teachername = null;
		PreparedStatement pstat = null;
		ResultSet rs = null;
		String sql = "select * from course where class like '%"+coursename+"%'";//表中有id和name这列
		try (Connection conn = JDBCUtil.getConnection()) {
			pstat = conn.prepareStatement(sql);
			//pstat.setString(1, name);
			rs = pstat.executeQuery();
			while(rs.next()){
				teachername = rs.getString("teacher");
			}
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		return teachername;
	}

}

